"""Build DAOS utilities"""


def scons():
    """Execute build"""

    Import('env', 'prereqs')

    if prereqs.server_requested():
        # Build daos_metrics
        SConscript('daos_metrics/SConscript')

        # Build ddb
        SConscript('ddb/SConscript')

        # Build dlck
        SConscript('dlck/SConscript')

    if not prereqs.client_requested():
        return

    env.d_add_build_rpath()

    # Build self test
    SConscript('self_test/SConscript')
    Default('self_test')

    if prereqs.test_requested():
        # Build wrapper libraries
        SConscript('wrap/SConscript')

        # Build crt_launch
        SConscript('crt_launch/SConscript')

    # Build cart_ctl
    SConscript('ctl/SConscript')

    denv = env.Clone()
    denv.AppendUnique(LIBPATH=[Dir('../client/dfs')])
    libs = ['daos', 'daos_common', 'uuid', 'dfs', 'duns', 'gurt', 'cart', 'dl']

    daos_hdlrs_src = ['daos_hdlr.c', 'daos_autotest.c', 'daos_dfs_hdlr.c']
    daos_hdlrs_lib = denv.d_library('daos_cmd_hdlrs', daos_hdlrs_src, LIBS=libs)
    env.Install('$PREFIX/lib64/', daos_hdlrs_lib)


if __name__ == "SCons.Script":
    scons()
